﻿using System.Collections.Generic;
using MashGen.Engine.Expressions;

namespace MashGen.Engine.Matching
{
    public class Match
    {
        private Dictionary<string, AbstractExpression> bindings;

        public Match(AbstractExpression root)
        {
            bindings = new Dictionary<string, AbstractExpression>();
            Root = root;
        }

        public AbstractExpression Root { get; private set; }

        public void AddBinding(string variable, AbstractExpression expression)
        {
            bindings[variable] = expression;
        }

        public bool TryGetBinding(string variable, out AbstractExpression expression)
        {
            return bindings.TryGetValue(variable, out expression);
        }

        public AbstractExpression this[string variable]
        {
            get { return bindings[variable]; }
        }

        public override string ToString()
        {
            return Root.ToString();
        }
    }
}
